package cn.laixueit.service.impl;

import cn.laixueit.mapper.EasyMapper;
import cn.laixueit.pojo.Easy;
import cn.laixueit.service.EasyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class EasyServiceImpl extends ServiceImpl<EasyMapper, Easy> implements EasyService {

    public Page<Easy> findPageCondtion(Integer startpage , Integer pagesize, Map map){
        Page<Easy> page = new Page<>(startpage, pagesize);
        QueryWrapper<Easy> wrapper = getCondtion(map);
        Page<Easy> easyPage = page(page, wrapper);
        return easyPage;
    }

    private QueryWrapper<Easy> getCondtion(Map map) {
        QueryWrapper<Easy> wrapper = new QueryWrapper<>();
        if(map!=null){
            if(map.get("title")!=null){
                wrapper.like("title",map.get("title"));
            }
            if(map.get("author")!=null){
                wrapper.like("author",map.get("author"));
            }
        }
        return  wrapper;
    }
}
